package classics.simulate;

import java.util.Arrays;
import java.util.Comparator;

public class test16 {
    //根据时间排序
    public static void main(String[] args) {
        String[] str = {"12:30:10","12:15:12","15:20:14"};
        String[] str2 = { "00:00:00","00:10:01","00:02:00","00:00:03"};

        Arrays.sort(str2, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int s1 = Integer.parseInt(o1.substring(0,2));
                int s2 = Integer.parseInt(o2.substring(0,2));
                int f1 = Integer.parseInt(o1.substring(3,5));
                int f2 = Integer.parseInt(o2.substring(3,5));
                int m1 = Integer.parseInt(o1.substring(6,8));
                int m2 = Integer.parseInt(o2.substring(6,8));
                if(m1==m2&&f1==f2){
                    return s1-s2;
                }else if(m1==m2){
                    return f1-f2;
                }else{
                    return m1-m2;
                }
            }
        });
        for(String s:str2){
            System.out.println(s);
        }
    }
}
